﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UserInterface.ClientApplication
{
	public partial class Statement : Form, IForm
	{
		public Statement()
		{
			InitializeComponent();
		}

		private void Statement_Load(object sender, EventArgs e)
		{
			DateTime startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

			DateFromDateTimePicker.Value = startDate;
			AccountComboBox.DataSource = fm.GetMyAccounts();
			AccountComboBox.DisplayMember = "Number";
			AccountComboBox.ValueMember = "Number";
		}

		public FormManager fm { get; set; }
		


		public DialogResult Show(FormManager fm)
		{
			this.fm = fm;
			return ShowDialog();
		}

		private void OKButton_Click(object sender, EventArgs e)
		{
			if(DateFromDateTimePicker.Value > DateToDateTimePicker.Value)
			{
				MessageBox.Show("Дата начала периода больше даты конца", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				
				return;
			}
			if (AccountComboBox.SelectedIndex != -1)
			{
				Object[] param = new Object[3];
                param[0] = DateFromDateTimePicker.Value;
				param[1] = DateToDateTimePicker.Value;
				param[2] = AccountComboBox.SelectedItem;
				fm.Param = param;
				StatementGrid st = new StatementGrid();
				st.Show(fm);
			}
			else {
				MessageBox.Show("Выберите счет", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
		}
	}
}
